﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;
using System.Web.Mvc;

namespace EHRForce.Models
{
    [Bind(Include = "PatientUID,LastName,FirstName,ChartNumber,MaritalStatus,DateOfBirth,Gender,SSN")]
    public partial class Patient
    {
        public bool IsValid
        {
            get { return (GetRuleViolations().Count() == 0); }
        }

        public IEnumerable<RuleViolation> GetRuleViolations()
        {
            if (String.IsNullOrEmpty(LastName))
                yield return new RuleViolation("Last Name is Required", "LastName");

            if (String.IsNullOrEmpty(FirstName))
                yield return new RuleViolation("First Name is Required", "FirstName");

            if (String.IsNullOrEmpty(ChartNumber))
                yield return new RuleViolation("Chart Number is Required", "ChartNumber");

            yield break;
        }

        partial void OnValidate(ChangeAction action)
        {
            if (!IsValid)
                throw new ApplicationException("Rule violations prevent saving");
        }
    }

}